<?php

class cl_Item
{
	var $Id;
	var $Title;
	var $hashId;
	
	function __construct($wholeItem) 
	{
		$this->SplitItem($wholeItem);
	}	
	
	private function SplitItem($wholeItem)
	{
		$arrTemp = explode('~',$wholeItem);
		$this->Id = $arrTemp[0];
		$this->Title = $arrTemp[1];
		$this->hashId = md5($this->Id.$this->Title);
	}
}

class cl_Basket
{
	protected $_Basket = array();

	
	function AddToBasket($item)
	{
		$index = $this->IsItemFound($item);
		if ($index==false)
		$this->_Basket[] = $item;
	}
	
	function RemoveFromBasket($item)
	{
		$temp_items = array();
		for ($i=0;$i<count($this->_items);$i++) 
		{
			if (isset($this->_Basket[$i])) 
			{
				if ($this->_Basket[$i]->hashId == $item_number->hashId)
					continue;
				else
					$temp_items[] = $this->_Basket[$i];
			}
		}
		$this->_Basket = $temp_items;
		unset($temp_items);
	}
	
	function IsItemFound($item_number)
	{
		for ($i=0;$i<count($this->_Basket);$i++) 
		{
			if (isset($this->_Basket[$i])) 
			{
				if ($this->_Basket[$i]->hashId == $item_number->hashId)
					return $i;
			}
		}
	 return false;
	}
	
	function GetBasket()
	{
		if(isset($this->_Basket))
		{
			return $this->_Basket;
		}
		else
		{
			return null;
		}
	}
	protected function SearchBasket($item)
	{
		
	}

	protected function LendBasketTo($arrBasket,$person)
	{
		
	}
	
	protected function BorrowBasketFrom($person)
	{
		
	}
	
	function RemoveItemByHashId($hashId) 
	{
		$temp_items = array();
		for ($i=0;$i<count($this->_Basket);$i++) 
		{
			if (isset($this->_Basket[$i])) 
			{
				if ($this->_Basket[$i]->hashId == $hashId)
					continue;
				else
					$temp_items[] = $this->_Basket[$i];
			}
		}
		$this->_Basket = $temp_items;
		unset($temp_items);
	}
	
	function GetItemByHashId($hashid)
	{
		$temp_items = array();
		for ($i=0;$i<count($this->_Basket);$i++) 
		{
			if (isset($this->_Basket[$i])) 
			{
				if ($this->_Basket[$i]->hashId == $hashId)
					return $this->_Basket[$i];
			}
		}
	}
	function EmptyBasket()
	{
		unset($this->_Basket);
		$this->_Basket = array();
	}
}
?>